package week_4;

public class MyRSortedLinkedList<E extends Comparable<E>>
{
	public ComparableRListNode<E> head_ = null;
	
	@Override
	public String toString()
	{
		if (head_ == null)
		{
			return "-empty-";
		}
		else
		{
			return head_.toString();
		}
	}
	
	public void add(E data)
	{
		if (head_ == null)
		{
			head_ = new ComparableRListNode<E>(data, null);
		}
		else
		{
			// head_.add(new ComparableRListNode<E>(data, null));
			if (data.compareTo(head_.data_) < 0)
			{
				head_ = new ComparableRListNode<E>(data, head_);
			}
			else
			{
				head_.add(new ComparableRListNode<E>(data, null));
			}
		}
	}
	
	public void delete(E data)
	{
		if (head_.data_.equals(data))
		{
			head_ = head_.next_;
		}
		else
		{
			head_.delete(new ComparableRListNode<E>(data, null));
		}
	}
	
	public static void main(String[] args)
	{
		MyRSortedLinkedList<Integer> list = new MyRSortedLinkedList<Integer>();
		list.add(10);
		System.out.println(list.toString());
		list.add(200);
		System.out.println(list.toString());
		list.add(-30);
		System.out.println(list.toString());
		list.add(50);
		System.out.println(list.toString());
		list.add(-40);
		System.out.println(list.toString());
		list.add(20);
		System.out.println(list.toString());
		
		list.delete(50);
		System.out.println(list.toString());
		list.delete(200);
		System.out.println(list.toString());
		list.delete(-40);
		System.out.println(list.toString());
		list.delete(15);
		System.out.println(list.toString());
	}
}
